package co.fitstart.scheduler.entity;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import com.demo2do.core.utils.DateUtils;

/**
 * 
 * @author dan
 *
 */
public class FinishedCourseReport {
    
    /** 课程总价 */
    private int price;
    
    /** 学员名称 */
    private String studentName;
    
    /** 学员电话 */
    private String studentMobile;
    
    /** 教练姓名 */
    private String coachName;
    
    private Date signinTime;
    
    private Long courseId;
    
    private Long siteId;
    
    private Long courseScheduleId;
    
    private int courseType;
    
    private String courseAmount;
    
    private int courseHours;
    
    private Date effectiveStart;
    
    private Date effectiveEnd;
    
    /**
     * The default constructor
     */
    public FinishedCourseReport() {
        
    }
    
    /**
     * 
     * @param lastScheduleDate
     * @return
     */
    public int calculateOffer() {
        int offer = 0;
        
        // calculate individual course offer
        if(this.courseType == 1 || this.courseType == 4 || this.courseType == 5) {
            
            if(StringUtils.isNotEmpty(this.courseAmount)) {
                offer = this.price/Integer.parseInt(this.courseAmount);
            } else {
                offer = this.price/this.courseHours;
            }
            
        } else if (this.courseType == 3) { // calculate year course offer
            long days = (this.effectiveEnd.getTime() - this.effectiveStart.getTime())/(24 * 60 * 60 * 1000);
            offer = new BigDecimal(this.price).divide(new BigDecimal(days), 2, RoundingMode.CEILING).intValue();
        }
        
        return offer;
    }
    
    /**
     * 
     * @param lastScheduleDate
     * @return
     */
    public Map<String, Object> describe() {
        Map<String, Object> result = new HashMap<String, Object>();
        
        result.put("offer", this.calculateOffer());
        result.put("studentName", this.studentName);
        result.put("studentMobile", this.studentMobile);
        result.put("coachName", this.coachName);
        result.put("occurTime", this.signinTime == null ? DateUtils.addDays(new Date(), -1) : this.signinTime);
        result.put("courseId", this.courseId);
        result.put("siteId", this.siteId);
        result.put("courseScheduleId", this.courseScheduleId);
        
        return result;
    }

    public Map<String, Object> describe(Date day) {
        Map<String, Object> result = new HashMap<String, Object>();
        
        result.put("offer", this.calculateOffer());
        result.put("studentName", this.studentName);
        result.put("studentMobile", this.studentMobile);
        result.put("coachName", this.coachName);
        result.put("occurTime", this.signinTime == null ? DateUtils.addDays(day, -1) : this.signinTime);
        result.put("courseId", this.courseId);
        result.put("siteId", this.siteId);
        result.put("courseScheduleId", this.courseScheduleId);
        
        return result;
    }

    /**
     * @return the price
     */
    public int getPrice() {
        return price;
    }

    /**
     * @return the studentName
     */
    public String getStudentName() {
        return studentName;
    }

    /**
     * @return the studentMobile
     */
    public String getStudentMobile() {
        return studentMobile;
    }

    /**
     * @return the coachName
     */
    public String getCoachName() {
        return coachName;
    }

    /**
     * @return the signinTime
     */
    public Date getSigninTime() {
        return signinTime;
    }

    /**
     * @return the courseId
     */
    public Long getCourseId() {
        return courseId;
    }

    /**
     * @return the siteId
     */
    public Long getSiteId() {
        return siteId;
    }

    /**
     * @return the courseScheduleId
     */
    public Long getCourseScheduleId() {
        return courseScheduleId;
    }

    /**
     * @return the courseType
     */
    public int getCourseType() {
        return courseType;
    }

    /**
     * @return the courseAmount
     */
    public String getCourseAmount() {
        return courseAmount;
    }

    /**
     * @return the courseHours
     */
    public int getCourseHours() {
        return courseHours;
    }

    /**
     * @return the effectiveStart
     */
    public Date getEffectiveStart() {
        return effectiveStart;
    }

    /**
     * @return the effectiveEnd
     */
    public Date getEffectiveEnd() {
        return effectiveEnd;
    }

    /**
     * @param price the price to set
     */
    public void setPrice(int price) {
        this.price = price;
    }

    /**
     * @param studentName the studentName to set
     */
    public void setStudentName(String studentName) {
        this.studentName = studentName;
    }

    /**
     * @param studentMobile the studentMobile to set
     */
    public void setStudentMobile(String studentMobile) {
        this.studentMobile = studentMobile;
    }

    /**
     * @param coachName the coachName to set
     */
    public void setCoachName(String coachName) {
        this.coachName = coachName;
    }

    /**
     * @param signinTime the signinTime to set
     */
    public void setSigninTime(Date signinTime) {
        this.signinTime = signinTime;
    }

    /**
     * @param courseId the courseId to set
     */
    public void setCourseId(Long courseId) {
        this.courseId = courseId;
    }

    /**
     * @param siteId the siteId to set
     */
    public void setSiteId(Long siteId) {
        this.siteId = siteId;
    }

    /**
     * @param courseScheduleId the courseScheduleId to set
     */
    public void setCourseScheduleId(Long courseScheduleId) {
        this.courseScheduleId = courseScheduleId;
    }

    /**
     * @param courseType the courseType to set
     */
    public void setCourseType(int courseType) {
        this.courseType = courseType;
    }

    /**
     * @param courseAmount the courseAmount to set
     */
    public void setCourseAmount(String courseAmount) {
        this.courseAmount = courseAmount;
    }

    /**
     * @param courseHours the courseHours to set
     */
    public void setCourseHours(int courseHours) {
        this.courseHours = courseHours;
    }

    /**
     * @param effectiveStart the effectiveStart to set
     */
    public void setEffectiveStart(Date effectiveStart) {
        this.effectiveStart = effectiveStart;
    }

    /**
     * @param effectiveEnd the effectiveEnd to set
     */
    public void setEffectiveEnd(Date effectiveEnd) {
        this.effectiveEnd = effectiveEnd;
    }

}
